<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css"/>   <#-- 自己的样式css -->
    <!--[if IE 6]>
    <script type="text/javascript" src="/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>角色管理</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    首页 <span class="c-gray en">&gt;</span>
    管理员管理 <span class="c-gray en">&gt;</span>
    角色管理
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray"> <span class="l">
        <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
            <i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
        <a class="btn btn-primary radius" id="add_admin_400" href="javascript:;">
            <i class="Hui-iconfont">&#xe600;</i>
            添加角色</a> </span>
    </div>
    <table id="role_table_400" lay-filter="table"></table>
    <script type="text/html" id="tableBar">
        <a class="layui-btn layui-btn-sm" id="admin_edit" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" id="admin_del" lay-event="del">删除</a>
    </script>
</div>
<#include "_footer.ftl"/>
<script type="text/javascript" src="/static/layui/layui.js"></script>

<script type="text/javascript">
    layui.use(['table','layer'],function(){
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.jquery;
        var tableIns = table.render({
            elem: '#role_table_400',
            url:"/dba/admin_role",
            page: true,
            request:{
                pageName:"pageNum",
                limitName:"pageSize"
            },
            cols: [[
                {type:'checkbox'},
                {field: 'roleId', title: 'ID',align:"center",sort: true, width:70},
                {field: 'roleName', title: '角色名',align:"center", width:120},
                {field: 'adminName', title: '用户列表',align:"center", width:300,
                    templet:function(d){
                        var str = JSON.stringify(d.adminName).replace(/\[|]/g,'').replace(/\"/g, "");
                        return str == ''?'无':JSON.stringify(d.adminName).replace(/\[|]/g,'').replace(/\"/g, "");
                    }
                },
                {field: 'details', title: '描述',align:"center", width:400},
                {title:'操作',align:"center",toolbar:'#tableBar'},
            ]],
        });

        table.on("tool(table)",function(onj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'edit'){

            }else if(layEvent === 'del'){
                layer.confirm("请谨慎删除,确定删除吗?",function(indexCon){
                    var id = data["roleId"] ;
                    $.ajax({
                        type:"POST",
                        url:"/dba/role_del",
                        dataType:"json",
                        data:{"id":id},
                        success:function(data){
                            if (data.ret === true){
                                layer.alert("删除成功!",{icon:1},function(){
                                    tableIns.reload({
                                        url:"/dba/admin_role"
                                    });
                                    layer.close(indexCon);
                                });
                            }else if (data.ret === false) {
                                layer.alert("删除失败!",{icon:2},function(){
                                    layer.close(indexCon);
                                });
                            }
                        },
                        error:function(data){
                            layer.open({
                                title:"异常",
                                icon:2,
                                content:"服务器异常！",
                                yes:function(){
                                    layer.close(indexCon);
                                }
                            });
                        },
                    });
                });
            }

        });

        /*管理员-角色-添加*/
        $("#add_admin_400").click(function(obj){
            layer.open({
                type: 2,
                area: [800+'px', 600 +'px'],
                fix: false, //不固定
                maxmin: true,
                shade:0.4,
                title: '添加角色',
                content: "/dba/admin_role_add",
                done:function(){
                    tableIns.reload({
                        url:"/dba/admin_role"
                    });
                },
            });
        });
    });

    /*$("#admin_del").click(function(){
        layer.open({
            type: 2,
            area: [800+'px', 600 +'px'],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: '编辑角色',
            content: '/dba/role_edit',
            done:function(){
                alert("测试");
            }
        });
    });*/

    /*管理员-角色-编辑*/
    function admin_role_edit(title,url,id,w,h){
        layer_show(title,url,w,h);
    }
    /*管理员-角色-删除*/
    function admin_role_del(obj,id){
        layer.confirm('角色删除须谨慎，确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '',
                dataType: 'json',
                success: function(data){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>